<template>
  <div class="app-container">
    <el-dialog
      class="media-account"
      title="选择账号"
      :visible.sync="dialogMediaAccountVisible"
      width="900px"
      :before-close="handleClose">
      <div class="media-account__main">
        <div class="media-account__main__left">
          <div class="head-container">
            <!--            <el-tree-->
            <!--              :data="classifyOptions"-->
            <!--              :props="defaultProps"-->
            <!--              :expand-on-click-node="false"-->
            <!--              :filter-node-method="filterNode"-->
            <!--              ref="tree"-->
            <!--              node-key="id"-->
            <!--              default-expand-all-->
            <!--              highlight-current-->
            <!--              @node-click="handleNodeClick"-->
            <!--            />-->
            <div v-for="(item,index) of mediaList" :key="index"
                 :class="['meida__main',item.id === activebg?'menusactiveClick':'']" @click="handleClickCHoose(item)">
              <div class="logo"> <img :src="require('@/assets/media/' + item.platformCode + '.png' )" style="width: 30px;height: 30px;border-radius: 50px"></div>
              <div class="name">{{ item.platformName }}</div>
            </div>
          </div>
        </div>
        <div class="media-account__main__right">
          <el-table max-height="300" v-loading="loading" :data="accountList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55"/>
            <el-table-column type="index" label="序号" width="60" show-overflow-tooltip/>
            <el-table-column label="呢称" min-width="180" show-overflow-tooltip>
              <template slot-scope="scope">
                <div style="display: flex; justify-content: start; align-items: center;">
                  <div style="display: flex; align-items: center;">
                    <img :src="scope.row.headImgUrl" style="width: 26px;height: 26px;border-radius: 50%">
                  </div>
                  <div style="margin-left: 10px">
                    {{ scope.row.nickname }}
                  </div>
                </div>
              </template>

            </el-table-column>

            <el-table-column label="平台" width="140">
              <template slot-scope="scope">
                <div style="display: flex; align-items: center;">
                  <div style="display: flex; align-items: center;">
<!--                    <img style="width: 26px; height: 26px; object-fit: cover;" :src="scope.row.platform.logo"/>-->
                    <img :src="require('@/assets/media/' + scope.row.platformCode + '.png' )" style="width: 30px;height: 30px;border-radius: 50px">
                  </div>
                  <div style="padding-left: 10px;">
                    {{ scope.row.platformName }}
                  </div>
                </div>
              </template>
            </el-table-column>
<!--            <el-table-column label="分组" align="center" prop="groupId" width="100">-->
<!--              <template slot-scope="scope">-->
<!--                {{ scope.row.group == null ? '无分组' : scope.row.group.treeName }}-->
<!--              </template>-->
<!--            </el-table-column>-->
            <el-table-column label="状态" align="center" prop="status" width="100">
              <template slot-scope="scope">
                <div v-if="scope.row.status=='0'" style="color: #33c300;font-weight: 600;">已登录</div>
                <div v-else style="color: red;font-weight: 600;">
                  <span>未登录</span>
                  <!--          <el-button size="mini">立即登录</el-button>-->
                </div>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </div>


      </div>
      <div style="text-align: end;margin-top: 25px">
        <el-button size="small" style="width: 90px" @click="dialogMediaAccountVisible=false">取消</el-button>
        <el-button type="primary" size="small" style="width: 90px" @click="handleClickChooseAccount">确定</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
import MediaAccount from "@/views/media/mediaAccount/index"
import {listMediaAccount } from "@/api/media/mediaAccount";
// import {listClassify, getClassify, delClassify, addClassify, updateClassify} from "@/api/media/classify";
import { listPlatform } from "@/api/media/platform";

export default {
  components: {MediaAccount},

  props: {
    showChildDialog: {
      type: Boolean,
      default: false
    },
    confirm: Function

  },

  computed: {
    dialogMediaAccountVisible: {
      get: function () {
        return this.showChildDialog
      },
      set: function (newValue) {
        this.$emit('update:showChildDialog', newValue) // 触发更新事件，父组件的showDialog会自动更新
      }
    }
  },
  data() {
    return {
      activebg: 0,
      // dialogMediaAccountVisible:true,
      MediaAccountGroupOptions: [],
      defaultProps: {
        children: "children",
        label: "treeName"
      },
      mediaList: [],
      classifyOptions: [],
      // 总条数
      total: 0,
      // 媒体帐号表格数据
      accountList: [],
      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nickname: undefined,
        platform: undefined,
        groupId: undefined,
        status: undefined,
        createTime: undefined, platformId: undefined

      },
      multipleSelection: [],

    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleClickChooseAccount() {
      this.confirm(this.multipleSelection)
      this.dialogMediaAccountVisible = false
    },
    getList() {
      this.loading = true;
      listMediaAccount(this.queryParams).then(response => {
        console.log(response)
        this.accountList = response.rows;
        this.total = response.total;
        this.loading = false;
      });

      // listClassify().then(response => {
      //   this.classifyOptions = [];
      //   const data = {id: 0, treeName: '无分类', children: []};
      //   data.children = this.handleTree(response.data, "id", "parentId");
      //   this.classifyOptions.push(data);
      // });

      listPlatform({pageNum: 1, pageSize: 50,status:1}).then(response => {
         console.log(response)
        this.mediaList = response.rows
      })
    },


    handleClose(done) {
      done()
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.groupId = data.id;
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
      this.multipleSelection = selection;
    },
    //选择平台
    handleClickCHoose(item) {
      this.activebg = item.platformCode
      console.log(item)
      this.queryParams.platformCode = item.platformCode
      this.getList()

    },


  }
}

</script>

<style lang="scss" scoped>


::-webkit-scrollbar {
  width: 4px;
  height: 10px;
  border-radius: 4px;
  background-color: #F5F5F5;
}
::-webkit-scrollbar-thumb {
  border-radius: 10px;
  -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);
  border-radius: 10px;
  background-image: -webkit-gradient(linear,left bottom,left top,color-stop(0.44, rgb(238, 130, 218)),color-stop(0.72, rgb(130, 192, 234)),color-stop(0.86, rgb(229, 146, 39)));
  transition: 0.3s ease-in-out;
}
::-webkit-scrollbar-track {
  border-radius: 10px;
  -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
  background-color: #F5F5F5;
}
.media-account {
  padding: 39px 0px;
  //border-radius: 18px !important;

  &__main {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    //align-items: center;

    &__left {
      width: 200px;
      margin-right: 20px;

      .head-container {
        height: 400px;
        overflow: auto;
      }
    }

    &__right {
      flex: 1;
    }
  }

}

::v-deep .el-dialog {
  border-radius: 7px !important;
}


.meida__main {
  display: flex;

  .logo {
    width: 30px;
    height: 30px;

    img {
      width: 100%;
      height: 100%;
    }

    margin-right: 10px;
  }

  padding: 8px 10px;
  margin: 10px 0;
  border-radius: 6px;
  cursor: pointer;

  &:hover {
    background-color: rgb(244, 247, 255);
    color: rgb(58, 100, 255);

    &:before {
      //content: "";
      //width: 4px;
      //height: 36px;
      //border-radius: 2px;
      //background-color: rgb(58, 100, 255);
      //position: absolute;
      //left: 0px;
    }
  }


}

.menusactiveClick {
  background-color: rgb(244, 247, 255);
  color: rgb(58, 100, 255);

  &:before {
    content: "";
    width: 4px;
    height: 36px;
    border-radius: 2px;
    background-color: rgb(58, 100, 255);
    position: absolute;
    left: 0px;
  }
}
</style>
